<?php


namespace app\api\middleware;

use app\common\model\User as Users;
use thans\jwt\exception\JWTException;
use thans\jwt\middleware\BaseMiddleware;

class CheckToken extends BaseMiddleware
{
    public function handle($request, \Closure $next)
    {
        try {
            $payload = $this->auth->auth();
            $request->uid = $payload['uid']->getValue();
            //查询用户信息
            $user_info = Users::find($request->uid);
            if (!$user_info){
                return json([
                    'code' => 507,
                    'msg' => '用户信息不存在'
                ]);
            }
//            if($user_info->status == 0){
//                return json([
//                    'code' => 508,
//                    'msg' => '用户已被禁用'
//                ]);
//            }
            $request->user_info = $user_info;
        } catch (JWTException $e) {
            return json([
                'code' => 506,
                'msg' => $e->getMessage()
            ]);
        }
        return $next($request);

    }

}